import 'package:demo/app/widgets/line_horizontal.dart';
import 'package:demo/model/agreement_model.dart';
import 'package:demo/theme/app_colors.dart';
import 'package:demo/theme/app_text_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import 'agreement_list_controller.dart';


class AgreementListView extends GetView<AgreementListController> {
  const AgreementListView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color_bg,
      appBar: AppBar(
        title:  Obx(()=>Text(controller.title.value,style: text_title_black)),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.only(top: 15.w),
        child: controller.obx((data) => setItem(data!),
          onLoading: Center(child: CupertinoActivityIndicator(radius: 15.w)),
          onEmpty: Center(child: Text('暂无协议',style: text_grey_16b.copyWith(fontSize: 24.sp))), //空数据显示
          onError: (error) => Center(child: Text('$error',style: text_grey_16b.copyWith(fontSize: 24.sp))), //出错界面显示
        ),
      ),
    );
  }

  setItem(List<Agreement> list) {
    return ListView.separated(
      padding: EdgeInsets.zero,
      itemCount: list.length,
      separatorBuilder: (BuildContext context, int index) => const LineHorizontal(),
      itemBuilder: (BuildContext context, int index) {
        return InkWell(
          highlightColor : Colors.transparent,
          splashColor: Colors.transparent,
          onTap: () => controller.toWebView(list[index]),
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 12.w,vertical: 12.w),
            color: Color_white,
            child: Row(
              mainAxisAlignment : MainAxisAlignment.spaceBetween,
              children: [
                Text('${list[index].name}',style: text_131732_14),
                SizedBox(width: 12.w),
                Image.asset('assets/images/ic_next.png',width: 15.w,height: 15.w)
              ],
            ),
          ),
        );
      },
    );
  }
}
